from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-05 14:12:38.918565
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 05, Feb, 2021
Time: 14:12:43
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.8764
Nobs: 193.000 HQIC: -46.7817
Log likelihood: 2199.20 FPE: 2.60458e-21
AIC: -47.3979 Det(Omega_mle): 1.65306e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.460009 0.141722 3.246 0.001
L1.Burgenland 0.101393 0.073599 1.378 0.168
L1.Kärnten -0.220411 0.060897 -3.619 0.000
L1.Niederösterreich 0.126484 0.170504 0.742 0.458
L1.Oberösterreich 0.222732 0.149108 1.494 0.135
L1.Salzburg 0.200069 0.078938 2.535 0.011
L1.Steiermark 0.100619 0.106373 0.946 0.344
L1.Tirol 0.153520 0.071263 2.154 0.031
L1.Vorarlberg -0.004032 0.065137 -0.062 0.951
L1.Wien -0.126540 0.143010 -0.885 0.376
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.498409 0.175202 2.845 0.004
L1.Burgenland 0.016802 0.090986 0.185 0.853
L1.Kärnten 0.365675 0.075283 4.857 0.000
L1.Niederösterreich 0.114791 0.210783 0.545 0.586
L1.Oberösterreich -0.146275 0.184331 -0.794 0.427
L1.Salzburg 0.194746 0.097586 1.996 0.046
L1.Steiermark 0.235062 0.131502 1.788 0.074
L1.Tirol 0.141029 0.088097 1.601 0.109
L1.Vorarlberg 0.177408 0.080524 2.203 0.028
L1.Wien -0.585870 0.176794 -3.314 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.303508 0.063092 4.811 0.000
L1.Burgenland 0.106470 0.032765 3.249 0.001
L1.Kärnten -0.021014 0.027110 -0.775 0.438
L1.Niederösterreich 0.069033 0.075905 0.909 0.363
L1.Oberösterreich 0.284767 0.066380 4.290 0.000
L1.Salzburg 0.005427 0.035142 0.154 0.877
L1.Steiermark -0.018704 0.047355 -0.395 0.693
L1.Tirol 0.091054 0.031725 2.870 0.004
L1.Vorarlberg 0.110299 0.028998 3.804 0.000
L1.Wien 0.074366 0.063665 1.168 0.243
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.221722 0.071973 3.081 0.002
L1.Burgenland -0.016106 0.037377 -0.431 0.667
L1.Kärnten 0.023744 0.030926 0.768 0.443
L1.Niederösterreich 0.032977 0.086590 0.381 0.703
L1.Oberösterreich 0.388585 0.075724 5.132 0.000
L1.Salzburg 0.095450 0.040088 2.381 0.017
L1.Steiermark 0.184558 0.054021 3.416 0.001
L1.Tirol 0.040775 0.036191 1.127 0.260
L1.Vorarlberg 0.090474 0.033079 2.735 0.006
L1.Wien -0.064696 0.072627 -0.891 0.373
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.529728 0.143347 3.695 0.000
L1.Burgenland 0.066232 0.074443 0.890 0.374
L1.Kärnten 0.013413 0.061595 0.218 0.828
L1.Niederösterreich -0.016860 0.172459 -0.098 0.922
L1.Oberösterreich 0.150637 0.150817 0.999 0.318
L1.Salzburg 0.052795 0.079843 0.661 0.508
L1.Steiermark 0.119558 0.107593 1.111 0.266
L1.Tirol 0.206989 0.072080 2.872 0.004
L1.Vorarlberg 0.028632 0.065883 0.435 0.664
L1.Wien -0.139709 0.144650 -0.966 0.334
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164483 0.101063 1.628 0.104
L1.Burgenland -0.019929 0.052484 -0.380 0.704
L1.Kärnten -0.013978 0.043426 -0.322 0.748
L1.Niederösterreich 0.127402 0.121588 1.048 0.295
L1.Oberösterreich 0.394788 0.106330 3.713 0.000
L1.Salzburg -0.022161 0.056291 -0.394 0.694
L1.Steiermark -0.032169 0.075856 -0.424 0.672
L1.Tirol 0.190398 0.050818 3.747 0.000
L1.Vorarlberg 0.037231 0.046449 0.802 0.423
L1.Wien 0.181627 0.101982 1.781 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.236388 0.129662 1.823 0.068
L1.Burgenland 0.067523 0.067336 1.003 0.316
L1.Kärnten -0.042995 0.055715 -0.772 0.440
L1.Niederösterreich -0.024737 0.155995 -0.159 0.874
L1.Oberösterreich -0.097610 0.136419 -0.716 0.474
L1.Salzburg 0.033223 0.072221 0.460 0.646
L1.Steiermark 0.390203 0.097321 4.009 0.000
L1.Tirol 0.493501 0.065198 7.569 0.000
L1.Vorarlberg 0.165671 0.059594 2.780 0.005
L1.Wien -0.219290 0.130840 -1.676 0.094
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080488 0.156620 0.514 0.607
L1.Burgenland 0.033221 0.081336 0.408 0.683
L1.Kärnten -0.090512 0.067298 -1.345 0.179
L1.Niederösterreich 0.249825 0.188428 1.326 0.185
L1.Oberösterreich -0.000773 0.164781 -0.005 0.996
L1.Salzburg 0.229942 0.087236 2.636 0.008
L1.Steiermark 0.125608 0.117555 1.069 0.285
L1.Tirol 0.072192 0.078754 0.917 0.359
L1.Vorarlberg 0.042301 0.071984 0.588 0.557
L1.Wien 0.264828 0.158043 1.676 0.094
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.594024 0.082788 7.175 0.000
L1.Burgenland -0.026334 0.042994 -0.613 0.540
L1.Kärnten -0.003299 0.035573 -0.093 0.926
L1.Niederösterreich -0.041533 0.099601 -0.417 0.677
L1.Oberösterreich 0.287810 0.087102 3.304 0.001
L1.Salzburg 0.018239 0.046112 0.396 0.692
L1.Steiermark 0.016020 0.062139 0.258 0.797
L1.Tirol 0.079478 0.041629 1.909 0.056
L1.Vorarlberg 0.138170 0.038050 3.631 0.000
L1.Wien -0.057841 0.083540 -0.692 0.489
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.140496 0.030520 0.208502 0.258961 0.070642 0.086039 -0.057078 0.170173
Kärnten 0.140496 1.000000 0.016481 0.193685 0.162357 -0.111995 0.167714 0.023894 0.312420
Niederösterreich 0.030520 0.016481 1.000000 0.311488 0.089000 0.220980 0.142045 0.054107 0.369572
Oberösterreich 0.208502 0.193685 0.311488 1.000000 0.305881 0.303726 0.119463 0.081204 0.138334
Salzburg 0.258961 0.162357 0.089000 0.305881 1.000000 0.153602 0.059391 0.085709 -0.016495
Steiermark 0.070642 -0.111995 0.220980 0.303726 0.153602 1.000000 0.112957 0.090194 -0.086887
Tirol 0.086039 0.167714 0.142045 0.119463 0.059391 0.112957 1.000000 0.160763 0.155919
Vorarlberg -0.057078 0.023894 0.054107 0.081204 0.085709 0.090194 0.160763 1.000000 0.073791
Wien 0.170173 0.312420 0.369572 0.138334 -0.016495 -0.086887 0.155919 0.073791 1.000000